package com.luyuan.crm.member.web.converter;

import java.util.Set;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.springframework.stereotype.Component;

import com.luyuan.crm.member.model.MemberGroup;

@Component("memberGroupsConverter")
public class MemberGroupsConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return null;
    }

    @SuppressWarnings("unchecked")
    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Set<MemberGroup> memberGroups = (Set<MemberGroup>) value;
        if (memberGroups == null || memberGroups.isEmpty()) {
            return null;
        }
        StringBuffer s = new StringBuffer();
        for (MemberGroup memberGroup : memberGroups) {
            s.append(memberGroup.getGroupName()).append("/");
        }
        return s.toString();
    }

}
